import { createRouter, createWebHashHistory } from "vue-router"

const initRouter = () => {
    // 获取routes内所有的路由模块并引入
    const requireRoutes = Object.values(import.meta.globEager("./routes/*.js"))
    let routes = []
    for (let i in requireRoutes) {
        routes.push(requireRoutes[i].default)
    }
    console.log(routes)
    return routes
}
const routes = [
    {
        path: "/",
        name: "index",
        redirect: "/home",
        component: () => import("@/layout/index.vue"),
        children: [...initRouter()],
    },
    {
        path: "/login",
        name: "login",
        component: () => import("@/views/login/index.vue"),
    },
]

const router = createRouter({ history: createWebHashHistory(), routes })

router.beforeEach((to, from, next) => {
    // 路由拦截
    // if (to.path !== "/Login") {
    //   if (sessionStorage.getItem("Authorization")) {
    //     next()
    //   } else {
    //     next("/Login")
    //   }
    // } else {
    next()
    // }
})
export default router
